Rust: Debugging and Profiling
Print
debug print
code: example.rs
struct Point {
x: i32,
y: i32,
}
let origin = Point { x: 0, y: 0 };
println!("The origin is: {:?}", origin);
dbg macro
(nightly version only for now)
code: example.rs
let a = 2;
let b = dbg!(a * 2) + 1;
assert_eq!(b, 5);
Type of variable
code: example.rs
fn type_of<T>(_: &T) -> &'static str {
unsafe { std::intrinsics::type_name::<T>() }
}
println!("{}", type_of(&x));
Logging
debug-assertions
debuginfo
debuginfo-lines
Backtrace
RUST_BACKTRACE=1
Debugger
gdb
LLDB + VSCode
Profiling
cargo-profiler